
const axios = require('axios');
const login = require("../axios/login");
const moment = require('moment');
let expireIn = 0;
async function getDingDingToken() {

  /**
   * 使用 Token 初始化账号Client
   * @return Client
   * @throws Exception
   * /v1.0/oauth2/corpAccessToken
   */
  axios({
    method: 'post',
    url: 'https://api.dingtalk.com/v1.0/oauth2/accessToken',
    headers: {
      'Content-Type': 'application/json'
    },
    data: {
      "appKey": "dingm9cmbrqukprpdldm",
      "appSecret": "kSq9puIiSAk6oPmz5yKmyalx1cgjuvovP6P9R56UAx3edKHpfrSOfnfDC5912M8s"
    }
  }).then((res) => {
    console.log("--------------------------------res.data---------------------------------")
    console.log(res.data);
    expireIn = res.data.expireIn;
    let dingdingTime = setInterval(() => {
      if (expireIn < 10) {
        clearInterval(dingdingTime)
        getDingDingToken();
      }
      expireIn = expireIn - 1;
      console.log(expireIn);
    }, 1000);
    // 登录
    console.log("login");
    login.Login(res.data);

  }).catch((error) => {
    console.log("------------------------error---------------");
    console.log(error);
    console.log("------------------------error---------------");

  })

}

module.exports = {
  getDingDingToken
} 